package com.weimob.mcloud.wechatwork.customer.mq.handler.group;

import com.weimob.mcloud.wechatwork.customer.domain.ExternalUserChangeInfo;
import com.weimob.mcloud.wechatwork.customer.mq.dto.CorpChatGroupDTO;

import java.util.Date;
import java.util.Objects;

/**
 * @author chenliuzhu
 * @date 2023/6/9
 */
public class ChatGroupConverter {

    public static void convert2CorpChatGroupDTO(ExternalUserChangeInfo externalUserChangeInfo, CorpChatGroupDTO dto){
        dto.setCorpId(externalUserChangeInfo.getToUserName());
        dto.setChatId(externalUserChangeInfo.getChatId());
        dto.setTemplateId(externalUserChangeInfo.getTemplateId());
        dto.setEvent(externalUserChangeInfo.getEvent());
        dto.setChangeType(externalUserChangeInfo.getChangeType());
        dto.setUpdateDetail(externalUserChangeInfo.getUpdateDetail());
        dto.setQuitDate(Objects.nonNull(externalUserChangeInfo.getQuitDate()) ? externalUserChangeInfo.getQuitDate() : new Date());
        dto.setQuitScene(externalUserChangeInfo.getQuitScene());
        dto.setIsInitGroup(externalUserChangeInfo.getIsInitGroup());
        dto.setTaskId(externalUserChangeInfo.getTaskId());
    }

    public static void convert2ExternalUserChangeInfo(ExternalUserChangeInfo userChangeInfo, CorpChatGroupDTO dto){
        userChangeInfo.setToUserName(dto.getCorpId());
        userChangeInfo.setChatId(dto.getChatId());
        userChangeInfo.setTemplateId(dto.getTemplateId());
        userChangeInfo.setEvent(dto.getEvent());
        userChangeInfo.setChangeType(dto.getChangeType());
        userChangeInfo.setUpdateDetail(dto.getUpdateDetail());
        userChangeInfo.setQuitScene(dto.getQuitScene());
        userChangeInfo.setQuitDate(dto.getQuitDate());
        userChangeInfo.setIsInitGroup(dto.getIsInitGroup());
        userChangeInfo.setTaskId(dto.getTaskId());
    }

}
